﻿using Dyao.Book.Application.Abstractions;
using Dyao.Book.BusApplication;
using Dyao.Book.Contract;
using Foundation.Core;

namespace Dyao.Book.Application
{
    public class SpiderManager : BaseManager, ISpiderManager
    {
        /// <inheritdoc cref="ISpiderManager.SyncSpierLogsAsync"/>
        public Task SyncSpierLogsAsync(List<OperationLogDto> spiderLogs)
        {
            ServiceBus.SendOneWayCommand<SpiderLogCommand>(new SpiderLogCommand()
            {
                Logs = spiderLogs
            });
            return Task.CompletedTask;
        }

        /// <inheritdoc cref="ISpiderManager.PushMessageAsync"/>
        public async Task PushMessageAsync(string sourceId, OperationTypeEnum logType, string message)
        {
            var logs = new List<OperationLogDto>()
            {
                new OperationLogDto(){
                    SourceId = sourceId,
                    OperationType = logType,
                    OperationLog = message.TrySubstring(0,1000)
                }
            };
            await SyncSpierLogsAsync(logs);
        }
    }
}
